const drawClock = require('../../utils/drawClock.js')

Page({
  timer:null,// 定时器
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    wx.createSelectorQuery().select('#myCanvas').fields({node:true,size:true})
    .exec(res=>{
      console.log(res[0])
      const canvas = res[0].node
      canvas.width=res[0].width
      canvas.height=res[0].height
      const draw = drawClock(canvas)
      draw()
      this.timer = setInterval(draw,1000)
    })
  },
  /**
   * 生命周期函数--监听页面卸载
   * 在页面卸载时清除定时器
   */
  onUnload() {
    clearInterval(this.timer)
  }
})